package br.ufrgs.dbproject.algorithm.dewey;

import java.util.Stack;

import br.ufrgs.dbproject.algorithm.IDStrategy;

public class DeweyID implements IDStrategy {
	
	private final String rawID;

	private Integer lastCreatedChildLocalID;

	protected final Stack<Integer> globalIDStack;

	protected DeweyID(Stack<Integer> globalIDStack) {

		this.globalIDStack = globalIDStack;
		
		this.lastCreatedChildLocalID = 0;
		this.rawID = DeweyIDUtils.createRawID(globalIDStack);
	}

	public DeweyID createChild() {
		
		Integer childLocalID = lastCreatedChildLocalID + 1;
		globalIDStack.push(childLocalID);
		lastCreatedChildLocalID = childLocalID;

		return new DeweyID(globalIDStack);
	}

	@Override
	public String toString() {
		return rawID;
	}
}
